//
//  FSLPageCollectionView.swift
//  FSLText
//
//  Created by 我演示 on 2019/11/6.
//  Copyright © 2019 ALLSall. All rights reserved.
//

import UIKit

class FSLPageCollectionView: UIView {
    fileprivate var titles : [String]
    fileprivate var layout : FSLPageCollectionViewLayout
    fileprivate var isTtileInTop : Bool
    fileprivate var style : FSLTitleStyle
        let collectionView : UICollectionView = UICollectionView()
    
    init(frame: CGRect , titles : [String] , style : FSLTitleStyle, isTitleInTop : Bool , layout: FSLPageCollectionViewLayout) {
        self.titles = titles
        self.isTtileInTop = isTitleInTop
        self.layout = layout
        self.style = style
      
        super.init(frame: frame)
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

/// 对外暴露的方法
extension FSLPageCollectionView  {
    func register(cell : AnyClass , identifier: String) {
        
    }
    
}



extension FSLPageCollectionView {
    fileprivate func setUpUI () {
        let titleY = isTtileInTop ? 0 : bounds.height  - style.titleHeight
        
        let titleFrame = CGRect(x: 0, y: titleY, width: bounds.width, height: style.titleHeight)
        
        let titleView = FSLTitleView(frame: titleFrame, titles: titles, style: style)
        addSubview(titleView)
        // 创建pageControll
        
        let pageControlHeight : CGFloat = 20
        let pageControllY = isTtileInTop ? (bounds.height - pageControlHeight) : (bounds.height - pageControlHeight - style.titleHeight)
        
        let pageControlFrame = CGRect(x: 0, y: pageControllY, width: bounds.width, height: pageControlHeight)
        
        let pageControl = UIPageControl(frame: pageControlFrame)
        
        pageControl.numberOfPages = 4
        addSubview(pageControl)
        
        ///3: 创建collectionView
        
        let collectionViewY = isTtileInTop ? style.titleHeight : 0
        let collectionViewFrame  = CGRect(x: 0, y: collectionViewY, width: bounds.width, height: bounds.height - style.titleHeight - pageControlHeight)
        let collectionView = UICollectionView(frame: collectionViewFrame , collectionViewLayout:  layout)
        addSubview(collectionView)
        
        
        
    }
    
}


extension FSLPageCollectionView : UICollectionViewDelegate {
    

    func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
        
    }
    private func scrollViewEndScroll() {
//        c
        let point = CGPoint(x: 100, y: 100)
        guard    let indexPath = collectionView.indexPathForItem(at: point) else {return}
        
        //2: 数据对接
//        pagec
        
        
    }
    
}
